@echo off

set env=%1%
set projectName=%2%
set nodeName=%3%
set today=%date:~0,4%%date:~5,2%%date:~8,2%
set rar="C:\Program Files\WinRAR\winrar.exe"
set zip="C:\Program Files\7-Zip\7z.exe"

echo "[Debug:info] projectName=%projectName%"
echo "[Debug:info] env=%env%"
echo "[Debug:info] nodeName=%nodeName%"

::set packagePath=C:\DevGasManager\DeployPackages\%projectName%_%today%.7z
set "packagePath="
IF "%env%" == "Dev20" (
	IF "%nodeName%" NEQ "Dev20" (
		echo "[Debug:info] skip deploy on %nodeName%"
		GOTO OK	
	)
	set "packagePath=C:\WEBSITE\DeployPackages\%projectName%_%today%.7z"
)
IF "%env%" == "lufei" (
	IF "%nodeName%" NEQ "lufei" (
		echo "[Debug:info] skip deploy on %nodeName%"
		GOTO OK	
	)
	set "packagePath=C:\Publish\DeployPackage\%projectName%_%today%.7z"
)

If not exist %packagePath% (
    echo "[Error:info] not exists package: %packagePath%"
    GOTO ERROR
)

set "webPath="
IF "%env%" == "Dev20" (
	IF "%projectName%" == "trunklpg" (
		set "webPath=C:\WEBSITE\dev.trunklpg"
	)
	IF "%projectName%" == "SaaSAPPlpg" (
		set "webPath=C:\WEBSITE\dev.saasapplpg"
	)
	IF "%projectName%" == "DccAdmin" (
		set "webPath=C:\WEBSITE\dev.dcc"
	)
	IF "%projectName%" == "NewWXShoplpg" (
		set "webPath=C:\WEBSITE\dev.wxshopapi"
	)
)
IF "%env%" == "lufei" (
	IF "%projectName%" == "trunklpg" (
		set "webPath=C:\Publish\trunklpg"
	)
	IF "%projectName%" == "SaaSAPPlpg" (
		set "webPath=C:\Publish\SaaSAPPlpg"
	)
	IF "%projectName%" == "DccAdmin" (
		set "webPath=C:\Publish\DccAdmin"
	)
	IF "%projectName%" == "NewWXShoplpg" (
		set "webPath=C:\Publish\NewWXShoplpg"
	)
)

IF "%webPath%" == "" (
	echo "[Error:info] not exists web path: %webPath%"
    GOTO ERROR
)

echo "[Debug:info] start unzip package to project folder: %webPath%"
::%rar% x %packagePath% C:\DevGasManager\dev.trunklpg
%zip% x %packagePath% -o%webPath% -aoa
IF %ERRORLEVEL% NEQ 0 GOTO ERROR

:OK
ECHO command success
EXIT 0

:ERROR
ECHO command failed
EXIT 1